<?php
class BasketController extends AppController {
	var $name = 'Basket';
	var $helpers = array();
	var $components = array('Menu','Init');
	var $uses = array();

	function beforeFilter() {
		$this->Init->startup($this);
		$this->Init->init();
		$this->Init->getKeyword();
		$_session = $this -> Session -> read();
		$this->loadModel('Hitcounter');
		$row = $this->Hitcounter->get(session_id());
		if ($row == 0) {
			$data = array(
				"session_id" => session_id(),
				"ref_url" => env("REQUEST_URI"),
				"ip_address" => env("REMOTE_ADDR"),
				"activity" => date("Y-m-d H:i:s")
			);
			$this->Hitcounter->save($data);
		}
		
                $this->set('activeNav', 'Home');
                $this->set('vipDiscount', $this->Session->read('discount_for_vip'));
	}

	function index() {
		$this->layout = 'inside';

		if (!$this->Session->read("lang")) {
			$lang = "vie";
		} else {
			$lang = $this->Session->read("lang");
		}

		Configure::write("Config.language", $lang);

		$orders = $this->Session->read('User.order');

		$this->set('orders', $orders);

		$this->set('lang',$lang);

	}

	function update() {
		$this->layout = null;
		$act = isset($_POST['act']) ? $_POST['act'] : 'update';
		$value = isset($_POST['value']) ? $_POST['value'] : 1;
		$id = isset($_POST['id']) ? intval($_POST['id']) : 28;
		echo $id, $act, $value;
		$orders = $this->Session->read('User.order');
		if ($id != null) {
			if ($act == 'update') {
				$orders[$id]['quantity'] = $value;
			}
			else {
				unset($orders[$id]);
			}
		}
		$this->Session->write('User.order', $orders);
	}
}
?>